home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Misc / InstallerNG / developer / gui / example / igui_AskOptions.c < prev    next >
C/C++ Source or Header  |  1999-10-31  |  5KB  |  172 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. /********************************************************************
  6.  *
  7.  *  DESCRIPTION
  8.  *
  9.  */
  10.  
  11. /********************************************************************
  12.  *
  13.  *  STATIC
  14.  *
  15.  */
  16.  
  17. static void __asm __saveds askoptions_hookfun(register __a2 APTR, register __a1 APTR *);
  18.  
  19. static const struct Hook askoptions_hook = { { NULL, NULL }, (VOID *) askoptions_hookfun, NULL, NULL };
  20.  
  21. /********************************************************************
  22.  *
  23.  *  EXTERN
  24.  *
  25.  */
  26.  
  27. /********************************************************************
  28.  *
  29.  *  PUBLIC
  30.  *
  31.  */
  32.  
  33. /********************************************************************
  34.  *
  35.  *  CODE
  36.  *
  37.  */
  38.  
  39. long __asm igui_AskOptions(register __a0 APTR application,
  40.                            register __a1 struct FunctionEnvironment *localenv)
  41. {
  42.   #ifdef DEBUG
  43.   DEBUG_MAKRO
  44.   #endif
  45.  
  46.   {
  47.     struct Application *app = (struct Application *) application;
  48.  
  49.     // the return value of this function
  50.     long retval = localenv->fe_Default;
  51.  
  52.     // for later use
  53.     APTR innergroup,
  54.  
  55.          // the new object
  56.          obj = GroupObject,
  57.                  Child, TextObject,
  58.                    MUIA_Frame, MUIV_Frame_None,
  59.                    MUIA_Text_Contents, localenv->fe_Prompt,
  60.                    MUIA_Text_SetMin, TRUE,
  61.                    MUIA_Text_PreParse, "\33c",
  62.                  End,
  63.                  Child, innergroup = GroupObject,
  64.                    MUIA_Group_Horiz, TRUE,
  65.                    Child, HVSpace,
  66.                      // here we will put the checkbox buttons later
  67.                  End,
  68.                End;
  69.  
  70.  
  71.  
  72.     // if DEFAULT equals -1 (means "all" choices on) then just set
  73.     // only the choices, which have relates nodes
  74.     if (retval == -1)
  75.     {
  76.       struct Node *node = (struct Node *) &(localenv->fe_Choices);
  77.  
  78.       retval = 0;
  79.       while (node = sav_GetSucc(node)) { retval |= (1 << node->ln_Pri); }
  80.     }
  81.  
  82.     if (!obj) { app->app_Error = GUIERROR_NO_GUI_OBJECT; }
  83.     else
  84.     {
  85.       // no dynamically create the labels and the checkboxs an
  86.       // put them together into the inner group!
  87.       if (DoMethod(innergroup, MUIM_Group_InitChange))
  88.       {
  89.         int i,j;
  90.         char *label;
  91.         APTR checkbox;
  92.         struct Node *choicenode = sav_GetHead((struct List *) &(localenv->fe_Choices));
  93.         long num_choices = sav_ListLen((struct List *) &(localenv->fe_Choices)),
  94.              columns = num_choices/10 + 1,
  95.              rows = num_choices/columns,
  96.              choice_id;
  97.  
  98.         // care for odd number of choices!
  99.         if (num_choices > (rows * columns)) { rows++; }
  100.  
  101.         // go!
  102.         for (j=1; j<=columns; j++)
  103.         {
  104.           APTR choicelist = GroupObject,
  105.                               MUIA_Group_Columns, 2,
  106.                               Child, HVSpace,
  107.                               Child, HVSpace,
  108.                             End;
  109.  
  110.           if (choicelist && DoMethod(choicelist, MUIM_Group_InitChange))
  111.           {
  112.             for (i=1; (i<=rows) && choicenode; i++)
  113.             {
  114.               // the node ln_Name holds the name, ln_Pri holds the related bit-number
  115.               label = choicenode->ln_Name;
  116.               choice_id = choicenode->ln_Pri;
  117.               choicenode = sav_GetSucc(choicenode);
  118.  
  119.               DoMethod(choicelist, OM_ADDMEMBER, Label(label));
  120.               DoMethod(choicelist, OM_ADDMEMBER, checkbox = CheckMark(retval & (1<<choice_id)), FALSE);
  121.  
  122.               // the hook
  123.               if (checkbox)
  124.               {
  125.                 SetAttrs(checkbox, MUIA_UserData, choice_id, TAG_DONE);
  126.                 DoMethod(checkbox, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  127.                          MUIV_Notify_Self, 3, MUIM_CallHook, &askoptions_hook, &retval);
  128.               }
  129.             }
  130.             DoMethod(choicelist, OM_ADDMEMBER, HVSpace);
  131.             DoMethod(choicelist, OM_ADDMEMBER, HVSpace);
  132.             DoMethod(choicelist, MUIM_Group_ExitChange);
  133.           }
  134.  
  135.           DoMethod(innergroup, OM_ADDMEMBER, choicelist);
  136.         }
  137.  
  138.         // unteren space einfügen und fertig
  139.         DoMethod(innergroup, OM_ADDMEMBER, HVSpace);
  140.         DoMethod(innergroup, MUIM_Group_ExitChange);
  141.       }
  142.  
  143.       // maybee BACK (if specified) or respect the swing mode
  144.       if (localenv->fe_Back)         { guistuff_SetBackButton(app, TRUE); }
  145.       else if (!app->app_SWING_Mode) { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  146.  
  147.       // add the content to the gui!
  148.       guistuff_NewContent(app, obj);
  149.  
  150.       //
  151.       igui_WaitApp(app);
  152.     }
  153.  
  154.     //
  155.     if (localenv->fe_Back) { guistuff_SetBackButton(app, FALSE); }
  156.  
  157.     igui_EmptyPanel(app);
  158.     return(retval);
  159.   }
  160. }
  161.  
  162. /********************************************************************/
  163.  
  164. static void __asm __saveds askoptions_hookfun(register __a2 APTR obj, register __a1 APTR *data)
  165. {
  166.   // data[0] holds the address of the "retval"
  167.  
  168.   long bitnum;
  169.   GetAttr(MUIA_UserData, obj, (APTR) &bitnum);
  170.   *((ULONG *) data[0]) = sav_BitChange(*((ULONG *) data[0]), bitnum);
  171. }
  172.